package com.gimi.cloud.jimi.manage.consumer.service.sys.impl;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.sys.SysMenuDTO;
import com.gimi.cloud.jimi.dto.params.MenuSingleParams;
import com.gimi.cloud.jimi.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.jimi.manage.consumer.service.sys.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class MenuServiceImpl implements MenuService{
    private static final Logger logger = LoggerFactory.getLogger(MenuServiceImpl.class);
    private final SystemFeignService systemFeignService;

    @Autowired
    public MenuServiceImpl(SystemFeignService systemFeignService){
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response getMenuList(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) {
        SysMenuDTO menuDTO = JsonUtil.jsonToBean(requestBody,SysMenuDTO.class);
        return systemFeignService.getMenuList(menuDTO);
    }

    @Override
    public Response getMenuSingle(String requestBody, HttpServletRequest request, HttpServletResponse response) {
        MenuSingleParams params = JsonUtil.jsonToBean(requestBody,MenuSingleParams.class);
        return systemFeignService.menuSingle(params);
    }

    @Override
    public Response addMenu(String requestBody, HttpServletRequest request, HttpServletResponse response) {
        SysMenuDTO menuDTO = JsonUtil.jsonToBean(requestBody,SysMenuDTO.class);
        return systemFeignService.menuAdd(menuDTO);
    }

    @Override
    public Response updateMenu(String requestBody, HttpServletRequest request, HttpServletResponse response) {
        SysMenuDTO menuDTO = JsonUtil.jsonToBean(requestBody,SysMenuDTO.class);
        return systemFeignService.menuUpdate(menuDTO);
    }

    @Override
    public Response deleteMenu(String requestBody, HttpServletRequest request, HttpServletResponse response) {
        SysMenuDTO menuDTO = JsonUtil.jsonToBean(requestBody,SysMenuDTO.class);
        if(null!=menuDTO && null!=menuDTO.getMeId()){
            return systemFeignService.menuDelete(menuDTO);
        }else{
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.MENU_DELETE_ERR);
            return resp;
        }
    }
}
